home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / kaffe-0.2 / kaffeh / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-17  |  1.7 KB  |  90 lines

  1. /*
  2.  * main.c
  3.  * Generate native code stubs from .class files.
  4.  *
  5.  * Copyright (c) 1996 Systems Architecture Research Centre,
  6.  *           City University, London, UK.
  7.  *
  8.  * See the file "license.terms" for information on usage and redistribution
  9.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  *
  11.  * Written by Tim Wilkinson <tim@sarc.city.ac.uk>, February 1996.
  12.  */
  13.  
  14. #include <stdio.h>
  15.  
  16. #define    BUFSZ    100
  17.  
  18. FILE* include;
  19. FILE* stub;
  20. char className[BUFSZ];
  21. char pathName[BUFSZ];
  22. char includeName[BUFSZ];
  23. char stubName[BUFSZ];
  24.  
  25. /*
  26.  * MAIN
  27.  */
  28. int
  29. main(int argc, char* argv[])
  30. {
  31.     FILE* fp;
  32.     char* nm;
  33.     int i;
  34.  
  35.     if (argc != 2) {
  36.         fprintf(stderr, "Usage: kaffeh <classname>\n");
  37.         exit(1);
  38.     }
  39.  
  40.     nm = argv[1];
  41.  
  42.     for (i = 0; nm[i] != 0; i++) {
  43.         switch (nm[i]) {
  44.         case '/':
  45.             className[i] = '_';
  46.             pathName[i] = nm[i];
  47.             includeName[i] = '.';
  48.             stubName[i] = '.';
  49.             break;
  50.         default:
  51.             className[i] = nm[i];
  52.             pathName[i] = nm[i];
  53.             includeName[i] = nm[i];
  54.             stubName[i] = nm[i];
  55.             break;
  56.         }
  57.     }
  58.     className[i] = 0;
  59.     pathName[i] = 0;
  60.     includeName[i] = 0;
  61.     stubName[i] = 0;
  62.     strcat(pathName, ".class");
  63.     strcat(includeName, ".h");
  64.     strcat(stubName, "Stub.c");
  65.  
  66.     fp = fopen(pathName, "r");;
  67.     if (fp == 0) {
  68.         fprintf(stderr, "Failed to open '%s'.\n", pathName);
  69.         exit(1);
  70.     }
  71.     include = fopen(includeName, "w");;
  72.     if (include == 0) {
  73.         fprintf(stderr, "Failed to create '%s'.\n", includeName);
  74.         exit(1);
  75.     }
  76.     stub = fopen(stubName, "w");;
  77.     if (stub == 0) {
  78.         fprintf(stderr, "Failed to create '%s'.\n", stubName);
  79.         exit(1);
  80.     }
  81.  
  82.     fprintf(stub, "/* DO NOT EDIT THIS FILE - it is machine generated */\n");
  83.     fprintf(stub, "#include <stubPreamble.h>\n");
  84.     fprintf(stub, "/* Stubs for class %s */\n", className);
  85.     readClass(fp);
  86.     fprintf(include, "\n#endif\n");
  87.  
  88.     exit(0);
  89. }
  90.